﻿using DataServer.Entities;
using DataServer.MySql;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IsPay.Logic
{
    public class AccuntSer
    {
        public Boolean CheckAccuntDouble(String columnname, String strvalue)
        {
            Boolean isdouble = false;
            try
            {
                SystemMag sm = new SystemMag();

                Accunt act = sm.GetAccuntbyColumnName(columnname, strvalue);
                if (act == null || act.AccuntId== null || act.AccuntName == null)
                {
                    isdouble = false;
                }
                else
                {
                    isdouble = true;
                }

            }
            catch (Exception e)
            {
                isdouble = false;
            }



            return isdouble;
        }

        public Boolean AddAccunt(Accunt accunt)
        {
            Boolean isadd = true;
            SystemMag sm = new SystemMag();
            isadd = sm.AddAccunt(accunt);
            return isadd;
        }
        public Accunt GetAccuntByIDPWD(String straccuntid,String actpwd)
        {
            SystemMag sm = new SystemMag();

            Accunt act = sm.GetAccuntByIDPWD(straccuntid, actpwd);

            return act;
        }
        public IEnumerable<Accunt> QueryAccunt(String accuntid, String accuntname, String isactive)
        {
            IEnumerable<Accunt> lsuser = new List<Accunt>();
            SystemMag sm = new SystemMag();

            lsuser = sm.QueryAccunt(accuntid, accuntname, isactive);

            return lsuser;
        }
        public String ModifyAccunt(List<Accunt> lsaccunt, String userid)
        {
            String strreturnmsg = "OK";
            foreach (Accunt accunt in lsaccunt)
            {
                if (accunt.IsActive == "1")
                {
                    String strrs = CheckAccuntBeforeUpdate(accunt);
                    if (strrs.Equals("OK"))
                    {

                    }
                    else
                    {
                        return strrs;
                    }
                }
            }
            SystemMag symg = new SystemMag();
            if (symg.ModifyAccunt(lsaccunt, userid))
            {

            }
            else
            {
                strreturnmsg = "更新失败!";
            }


            return strreturnmsg;
        }
        public String CheckAccuntBeforeUpdate(Accunt accunt)
        {
            
            return "OK";
        }


        public Boolean CheckBackAccuntDouble(String columnname, String strvalue)
        {
            Boolean isdouble = false;
            try
            {
                SystemMag sm = new SystemMag();

                BankCardAccunt act = sm.GetBankAccuntbyColumnName(columnname, strvalue);
                if (act == null || act.BankCardNo == null || act.BankCardKey == null)
                {
                    isdouble = false;
                }
                else
                {
                    isdouble = true;
                }

            }
            catch (Exception e)
            {
                isdouble = false;
            }



            return isdouble;
        }

        public Boolean AddBankCardAccunt(BankCardAccunt bankaccunt,String userid)
        {
            Boolean isadd = true;
            SystemMag sm = new SystemMag();
            isadd = sm.AddBankCardAccunt(bankaccunt, userid);
            return isadd;
        }
    }
}